```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Zookeeper Leader选举机制解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
            z-index: 1;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(102, 126, 234, 0.2);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover:after {
            height: 60%;
        }
        .dropcap:first-letter {
            float: left;
            font-family: 'Noto Serif SC', serif;
            font-size: 5rem;
            line-height: 0.75;
            margin: 0.15em 0.1em 0 0;
            color: #667eea;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-6xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 serif">Zookeeper <span class="highlight">Leader选举</span>机制</h1>
                    <p class="text-xl opacity-90 mb-8">分布式系统高可用性与一致性的核心保障</p>
                    <div class="flex items-center">
                        <div class="w-12 h-12 rounded-full bg-white text-purple-700 flex items-center justify-center mr-4">
                            <i class="fas fa-server text-2xl"></i>
                        </div>
                        <p class="text-sm opacity-80">分布式一致性 / 高可用架构 / 集群管理</p>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="bg-white bg-opacity-10 p-8 rounded-xl backdrop-filter backdrop-blur-sm border border-white border-opacity-20">
                        <div class="mermaid">
                            graph TD
                                A[Zookeeper集群] --> B[Leader选举]
                                B --> C1[Leader节点]
                                B --> C2[Follower节点]
                                C1 --> D[处理所有写操作]
                                C2 --> E[处理读操作]
                                C1 --> F[协调事务提交]
                                C1 --> G[数据同步]
                                H[选举触发] -->|集群启动| B
                                H -->|Leader失效| B
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Content Section -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-4xl">
            <!-- Overview -->
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-16 card-hover">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-10 h-10 rounded-full bg-purple-100 text-purple-700 flex items-center justify-center mr-4">
                            <i class="fas fa-sitemap"></i>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800 serif">选举过程概述</h2>
                    </div>
                    <div class="dropcap text-gray-700 mb-6">
                        Zookeeper 集群由多个节点组成，每个节点都有可能成为 Leader。在集群启动时或 Leader 节点失效时，Zookeeper 需要进行 Leader 选举。选举的过程包括以下步骤：
                    </div>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="bg-purple-50 p-6 rounded-lg">
                            <div class="text-purple-700 mb-3">
                                <i class="fas fa-play-circle text-2xl"></i>
                            </div>
                            <h3 class="font-bold text-lg mb-2">初始化</h3>
                            <p class="text-gray-600">每个节点在启动时会发送一个选举请求，声明自己有意成为 Leader。</p>
                        </div>
                        <div class="bg-blue-50 p-6 rounded-lg">
                            <div class="text-blue-700 mb-3">
                                <i class="fas fa-project-diagram text-2xl"></i>
                            </div>
                            <h3 class="font-bold text-lg mb-2">选举算法</h3>
                            <p class="text-gray-600">使用 ZAB（Zookeeper Atomic Broadcast）协议中的 Leader 选举算法。</p>
                        </div>
                        <div class="bg-green-50 p-6 rounded-lg">
                            <div class="text-green-700 mb-3">
                                <i class="fas fa-check-circle text-2xl"></i>
                            </div>
                            <h3 class="font-bold text-lg mb-2">选举结果</h3>
                            <p class="text-gray-600">最终会选出一个 Leader，其他节点成为 Follower。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Algorithm Details -->
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-16 card-hover">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-10 h-10 rounded-full bg-blue-100 text-blue-700 flex items-center justify-center mr-4">
                            <i class="fas fa-code-branch"></i>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800 serif">Leader 选举的算法</h2>
                    </div>
                    <p class="text-gray-700 mb-6">Zookeeper 的 Leader 选举算法是基于 <strong>ZAB 协议</strong>（Zookeeper Atomic Broadcast），其算法过程如下：</p>
                    
                    <div class="mb-8">
                        <div class="flex items-start mb-4">
                            <span class="flex-shrink-0 bg-blue-100 text-blue-800 text-xs font-semibold mr-2 px-2.5 py-0.5 rounded">2.1</span>
                            <h3 class="text-xl font-semibold text-gray-800">启动选举</h3>
                        </div>
                        <div class="ml-8 pl-4 border-l-2 border-blue-200">
                            <p class="text-gray-700 mb-3"><span class="font-medium text-blue-600">广播选举请求：</span>每个节点启动时会发送一个选举请求到集群中的所有其他节点，声明自己希望成为 Leader。</p>
                            <p class="text-gray-700"><span class="font-medium text-blue-600">接收请求：</span>其他节点接收到选举请求后，会记录下请求的候选者信息，并回复选举结果。</p>
                        </div>
                    </div>

                    <div class="mb-8">
                        <div class="flex items-start mb-4">
                            <span class="flex-shrink-0 bg-blue-100 text-blue-800 text-xs font-semibold mr-2 px-2.5 py-0.5 rounded">2.2</span>
                            <h3 class="text-xl font-semibold text-gray-800">选举过程</h3>
                        </div>
                        <div class="ml-8 pl-4 border-l-2 border-blue-200">
                            <div class="mb-6">
                                <h4 class="font-medium text-gray-800 mb-2">1. 初始化阶段</h4>
                                <p class="text-gray-700">每个节点在启动时会生成一个唯一的 <code class="bg-gray-100 px-1 rounded">zxid</code>（Zookeeper Transaction ID），用来标识节点的事务状态。节点会根据 <code class="bg-gray-100 px-1 rounded">zxid</code> 和 <code class="bg-gray-100 px-1 rounded">节点ID</code> 来发起选举请求。</p>
                            </div>
                            <div class="mb-6">
                                <h4 class="font-medium text-gray-800 mb-2">2. 选举请求和投票</h4>
                                <p class="text-gray-700">节点将自己的 <code class="bg-gray-100 px-1 rounded">zxid</code> 和 <code class="bg-gray-100 px-1 rounded">节点ID</code> 发送给集群中的其他节点。每个节点在接收到选举请求后，比较请求中的 <code class="bg-gray-100 px-1 rounded">zxid</code> 和自己节点的 <code class="bg-gray-100 px-1 rounded">zxid</code>，并根据规则进行投票。</p>
                            </div>
                            <div class="mb-6">
                                <h4 class="font-medium text-gray-800 mb-2">3. 选举规则</h4>
                                <div class="bg-gray-50 p-4 rounded-lg">
                                    <p class="text-gray-700 mb-2"><span class="font-medium text-purple-600">最高 zxid 优先：</span>节点会选择具有最高 <code class="bg-gray-100 px-1 rounded">zxid</code> 的候选者作为 Leader。</p>
                                    <p class="text-gray-700"><span class="font-medium text-purple-600">节点ID比较：</span>如果多个候选者的 <code class="bg-gray-100 px-1 rounded">zxid</code> 相同，则比较节点 ID，节点 ID 较小的优先。</p>
                                </div>
                            </div>
                            <div class="mb-6">
                                <h4 class="font-medium text-gray-800 mb-2">4. 达成一致</h4>
                                <p class="text-gray-700">节点根据收到的投票结果来决定最终的 Leader。一旦某个节点获得了集群中大多数节点的选票，它就会被选举为 Leader。</p>
                            </div>
                        </div>
                    </div>

                    <div class="mb-8">
                        <div class="flex items-start mb-4">
                            <span class="flex-shrink-0 bg-blue-100 text-blue-800 text-xs font-semibold mr-2 px-2.5 py-0.5 rounded">2.3</span>
                            <h3 class="text-xl font-semibold text-gray-800">确认和同步</h3>
                        </div>
                        <div class="ml-8 pl-4 border-l-2 border-blue-200">
                            <p class="text-gray-700 mb-3"><span class="font-medium text-blue-600">Leader 确认：</span>当 Leader 被选举出来后，其他节点会更新自己的状态，成为 Follower。</p>
                            <p class="text-gray-700"><span class="font-medium text-blue-600">数据同步：</span>Leader 节点会与 Follower 节点进行数据同步，确保所有节点的数据一致性。</p>
                        </div>
                    </div>

                    <div class="bg-blue-50 p-6 rounded-lg">
                        <div class="mermaid">
                            sequenceDiagram
                                participant Node1
                                participant Node2
                                participant Node3
                                Note over Node1,Node3: 1. 选举请求
                                Node1->>Node2: 选举请求(zxid=1, id=1)
                                Node1->>Node3: 选举请求(zxid=1, id=1)
                                Node2->>Node1: 选举请求(zxid=2, id=2)
                                Node2->>Node3: 选举请求(zxid=2, id=2)
                                Node3->>Node1: 选举请求(zxid=3, id=3)
                                Node3->>Node2: 选举请求(zxid=3, id=3)
                                Note over Node1,Node3: 2. 投票比较
                                Node1->>Node3: 投票(zxid=3最高)
                                Node2->>Node3: 投票(zxid=3最高)
                                Note over Node1,Node3: 3. 选举结果
                                Node3-->>Node1: 成为Leader
                                Node3-->>Node2: 成为Leader
                        </div>
                    </div>
                </div>
            </div>

            <!-- Key Points -->
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-10 h-10 rounded-full bg-green-100 text-green-700 flex items-center justify-center mr-4">
                            <i class="fas fa-key"></i>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800 serif">选举算法的关键点</h2>
                    </div>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="border-l-4 border-purple-500 pl-4 py-2">
                            <h3 class="font-bold text-lg mb-2 text-purple-700">一致性</h3>
                            <p class="text-gray-600">ZAB 协议确保了 Leader 选举的一致性，所有节点都同意选举结果。</p>
                        </div>
                        <div class="border-l-4 border-blue-500 pl-4 py-2">
                            <h3 class="font-bold text-lg mb-2 text-blue-700">高可用性</h3>
                            <p class="text-gray-600">选举算法允许集群中断、节点失效后继续进行选举，确保系统的高可用性。</p>
                        </div>
                        <div class="border-l-4 border-green-500 pl-4 py-2">
                            <h3 class="font-bold text-lg mb-2 text-green-700">故障恢复</h3>
                            <p class="text-gray-600">如果 Leader 节点失效，集群会自动进行 Leader 重新选举，保证系统的持续运行。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-10 px-4">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-sm">深入探讨分布式系统核心技术</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-white hover:text-purple-300 transition-colors duration-300">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-sm">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            sequenceDiagram: {
                useMaxWidth: true,
                height: 300
            }
        });
    </script>
</body>
</html>
```